package com.opencloud.ywt.provider.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opencloud.common.model.PageParams;
import com.opencloud.common.model.ResultBody;
import com.opencloud.ywt.client.model.entity.*;
import com.opencloud.ywt.provider.service.BhyfCityService;
import com.opencloud.ywt.provider.service.BhyfDzbpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 电子班牌
 * @author yeyong
 */
@Slf4j
@RestController
@Api(value = "电子班牌", tags = "电子班牌")
public class BhyfDzbpController {
    @Autowired
    private BhyfDzbpService bhyfDzbpService;

    /**
     * 获取通知
     * @param map
     * @return
     */
    @ApiOperation(value = "获取通知", notes = "获取通知")
    @GetMapping("/dzbp/noticelist")
    public ResultBody<List<BhyfDzbpNotice>> getNoticeListPage(
            @RequestParam(required = false) Map map
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findNoticeListPage(new PageParams(map)));
    }


    /**
     * 获取教师风采
     * @param map
     * @return
     */
    @ApiOperation(value = "获取教师风采", notes = "获取教师风采")
    @GetMapping("/dzbp/teacherlist")
    public ResultBody<List<BhyfDzbpTeacher>> getTeacherListPage(
            @RequestParam(required = false) Map map
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findTeacherListPage(new PageParams(map)));
    }

    /**
     * 获取值日列表
     * @param map
     * @return
     */
    @ApiOperation(value = "获取值日列表", notes = "获取值日列表")
    @GetMapping("/dzbp/dutylist")
    public ResultBody<List<BhyfDzbpDuty>> getDutyListPage(
            @RequestParam(required = false) Map map
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findDutyListPage(new PageParams(map)));
    }

    /**
     * 获取文件列表
     * @param map
     * @return
     */
    @ApiOperation(value = "获取文件列表", notes = "获取文件列表")
    @GetMapping("/dzbp/filelist")
    public ResultBody<List<BhyfDzbpFile>> getFileListPage(
            @RequestParam(required = false) Map map
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findFileListPage(new PageParams(map)));
    }

    /**
     * 新增文件信息
     * @param filekey
     * @param filesize
     * @param filetype
     * @param fileurl
     * @param gid
     * @param classid
     * @param classname
     * @param uid
     * @param uname
     * @return
     */
    @ApiOperation(value = "新增文件信息", notes = "新增文件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "filekey", value = "文件Key", required = true, paramType = "form"),
            @ApiImplicitParam(name = "fileurl", value = "文件路径", required = true, paramType = "form"),
            @ApiImplicitParam(name = "filetype", value = "文件类型 图片=1 视频=2", required = true, paramType = "form"),
            @ApiImplicitParam(name = "filesize", value = "文件大小 单位KB", required = true, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classname", value = "班级名称", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uid", value = "登录人ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uname", value = "登录人姓名", required = true, paramType = "form")
    })
    @PostMapping("/dzbp/addfile")
    public ResultBody<BhyfDzbpFile> addfile(
            @RequestParam(name = "filekey") String filekey,
            @RequestParam(name = "filesize") Integer filesize,
            @RequestParam(name = "filetype") Integer filetype,
            @RequestParam(name = "fileurl") String fileurl,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "classname") String classname,
            @RequestParam(name = "uid") Integer uid,
            @RequestParam(name = "uname") String uname
    )
    {
        BhyfDzbpFile entiy = new BhyfDzbpFile();
        entiy.setUid(uid);
        entiy.setUname(uname);
        entiy.setClassname(classname);
        entiy.setClassid(classid);
        entiy.setGid(gid);
        entiy.setFilekey(filekey);
        entiy.setFilesize(filesize);
        entiy.setFileurl(fileurl);
        entiy.setFiletype(filetype);
        entiy.setStatus(1);
        return ResultBody.ok().data(bhyfDzbpService.addFile(entiy));
    }

    /**
     * 新增通知信息
     * @param contents
     * @param startdate
     * @param enddate
     * @param gid
     * @param classid
     * @param classname
     * @param uid
     * @param uname
     * @return
     */
    @ApiOperation(value = "新增通知信息", notes = "新增通知信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contents", value = "通知内容", required = true, paramType = "form"),
            @ApiImplicitParam(name = "startdate", value = "开始日期", required = true, paramType = "form"),
            @ApiImplicitParam(name = "enddate", value = "结束日期", required = true, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classname", value = "班级名称", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uid", value = "登录人ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uname", value = "登录人姓名", required = true, paramType = "form")
    })
    @PostMapping("/dzbp/addnotice")
    public ResultBody<BhyfDzbpNotice> addnotice(
            @RequestParam(name = "contents") String contents,
            @RequestParam(name = "startdate") String  startdate,
            @RequestParam(name = "enddate") String enddate,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "classname") String classname,
            @RequestParam(name = "uid") Integer uid,
            @RequestParam(name = "uname") String uname
    )
    {
        BhyfDzbpNotice entiy = new BhyfDzbpNotice();
        entiy.setUid(uid);
        entiy.setUname(uname);
        entiy.setClassname(classname);
        entiy.setClassid(classid);
        entiy.setGid(gid);
        entiy.setContents(contents);
        entiy.setStartdate(startdate);
        entiy.setEnddate(enddate);
        entiy.setStatus(1);
        return ResultBody.ok().data(bhyfDzbpService.addNotice(entiy));
    }

    /**
     * 新增教师信息
     * @param teachername
     * @param teacherlogo
     * @param teacherinfo
     * @param gid
     * @param classid
     * @param classname
     * @param uid
     * @param uname
     * @return
     */
    @ApiOperation(value = "新增教师信息", notes = "新增教师信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teachername", value = "老师姓名", required = true, paramType = "form"),
            @ApiImplicitParam(name = "teacherlogo", value = "老师头像", required = true, paramType = "form"),
            @ApiImplicitParam(name = "teacherinfo", value = "老师简介", required = true, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classname", value = "班级名称", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uid", value = "登录人ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "uname", value = "登录人姓名", required = true, paramType = "form")
    })
    @PostMapping("/dzbp/addteacher")
    public ResultBody<BhyfDzbpTeacher> addteacher(
            @RequestParam(name = "teachername") String teachername,
            @RequestParam(name = "teacherlogo") String teacherlogo,
            @RequestParam(name = "teacherinfo") String teacherinfo,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "classname") String classname,
            @RequestParam(name = "uid") Integer uid,
            @RequestParam(name = "uname") String uname
    )
    {
        BhyfDzbpTeacher entiy = new BhyfDzbpTeacher();
        entiy.setUid(uid);
        entiy.setUname(uname);
        entiy.setClassname(classname);
        entiy.setClassid(classid);
        entiy.setGid(gid);
        entiy.setTeacherinfo(teacherinfo);
        entiy.setTeacherlogo(teacherlogo);
        entiy.setTeachername(teachername);
        entiy.setStatus(1);
        return ResultBody.ok().data(bhyfDzbpService.addTeacher(entiy));
    }

    /**
     * 新增值日信息
     * @param dutydate
     * @param studentname
     * @param studentlogo
     * @param personid
     * @param gid
     * @param classid
     * @param classname
     * @return
     */
    @ApiOperation(value = "新增值日信息", notes = "新增值日信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dutydate", value = "值日日期", required = true, paramType = "form"),
            @ApiImplicitParam(name = "studentname", value = "学生头像", required = true, paramType = "form"),
            @ApiImplicitParam(name = "studentlogo", value = "学生姓名", required = true, paramType = "form"),
            @ApiImplicitParam(name = "personid", value = "学生ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classname", value = "班级名称", required = true, paramType = "form")
    })
    @PostMapping("/dzbp/addduty")
    public ResultBody<BhyfDzbpDuty> addduty(
            @RequestParam(name = "dutydate") String dutydate,
            @RequestParam(name = "studentname") String studentname,
            @RequestParam(name = "studentlogo") String studentlogo,
            @RequestParam(name = "personid") Integer personid,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "classname") String classname
    )
    {
        BhyfDzbpDuty entiy = new BhyfDzbpDuty();
        entiy.setClassname(classname);
        entiy.setClassid(classid);
        entiy.setGid(gid);
        entiy.setDutydate(dutydate);
        entiy.setStudentlogo(studentlogo);
        entiy.setStudentname(studentname);
        entiy.setPersonid(personid);
        return ResultBody.ok().data(bhyfDzbpService.addDuty(entiy));
    }

    /**
     * 删除通知
     * @param noticeid
     * @param gid
     * @param classid
     * @param uid
     * @return
     */
    @ApiOperation(value = "删除通知", notes = "删除通知")
    @PostMapping("/dzbp/deletenotice")
    public ResultBody<Boolean> deletenotice(
            @RequestParam(name = "noticeid") Integer noticeid,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "uid") Integer uid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.deleteNotice(noticeid,gid,classid,uid));
    }

    @ApiOperation(value = "删除教师", notes = "删除教师")
    @PostMapping("/dzbp/deleteteacher")
    public ResultBody<Boolean> deleteteacher(
            @RequestParam(name = "teacherid") Integer teacherid,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.deleteTeacher(teacherid,gid,classid));
    }

    @ApiOperation(value = "删除文件", notes = "删除文件")
    @PostMapping("/dzbp/deletefile")
    public ResultBody<Boolean> deletefile(
            @RequestParam(name = "filekey") String filekey,
            @RequestParam(name = "gid") Integer gid,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "uid") Integer uid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.deleteFile(filekey,gid,classid,uid));
    }

    @ApiOperation(value = "更新老师信息", notes = "更新老师信息")
    @PostMapping("/dzbp/updateteacher")
    public ResultBody<BhyfDzbpTeacher> updateteacher(
            @RequestParam(name = "teachername") String teachername,
            @RequestParam(name = "teacherlogo") String teacherlogo,
            @RequestParam(name = "teacherinfo") String teacherinfo,
            @RequestParam(name = "teacherid") Integer teacherid
    )
    {
        BhyfDzbpTeacher entiy = new BhyfDzbpTeacher();
        entiy.setTeacherinfo(teacherinfo);
        entiy.setTeacherlogo(teacherlogo);
        entiy.setTeachername(teachername);
        entiy.setId(teacherid);
        return ResultBody.ok().data(bhyfDzbpService.updateTeacher(entiy));
    }

    @ApiOperation(value = "删除区域", notes = "删除区域")
    @PostMapping("/dzbp/deletearea")
    public ResultBody<Boolean> deletearea(
            @RequestParam(name = "areaid") Integer areaid,
            @RequestParam(name = "gid") Integer gid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.deleteArea(areaid,gid));
    }

    @ApiOperation(value = "新增区域", notes = "新增区域")
    @PostMapping("/dzbp/addarea")
    public ResultBody<BhyfDzbpArea> addarea(
            @RequestParam(name = "areaname") String areaname,
            @RequestParam(name = "areaurl") String areaurl,
            @RequestParam(name = "areax") Float areax,
            @RequestParam(name = "areay") Float areay,
            @RequestParam(name = "gid") Integer gid
    )
    {
        BhyfDzbpArea entiy = new BhyfDzbpArea();
        entiy.setAreaname(areaname);
        entiy.setAreaurl(areaurl);
        entiy.setGid(gid);
        entiy.setAreax(areax);
        entiy.setAreay(areay);
        return ResultBody.ok().data(bhyfDzbpService.addArea(entiy));
    }

    @ApiOperation(value = "新增地图", notes = "新增地图")
    @PostMapping("/dzbp/addmap")
    public ResultBody<BhyfDzbpMap> addmap(
            @RequestParam(name = "mapurl") String mapurl,
            @RequestParam(name = "mapwidth") Integer mapwidth,
            @RequestParam(name = "mapheight") Integer mapheight,
            @RequestParam(name = "mapbili") Float mapbili,
            @RequestParam(name = "gid") Integer gid
    )
    {
        BhyfDzbpMap entiy = new BhyfDzbpMap();
        entiy.setMapbili(mapbili);
        entiy.setMapheight(mapheight);
        entiy.setGid(gid);
        entiy.setMapurl(mapurl);
        entiy.setMapwidth(mapwidth);
        return ResultBody.ok().data(bhyfDzbpService.addMap(entiy));
    }

    @ApiOperation(value = "更新区域", notes = "更新区域")
    @PostMapping("/dzbp/updatearea")
    public ResultBody<BhyfDzbpArea> updatearea(
            @RequestParam(name = "areaname") String areaname,
            @RequestParam(name = "areaurl") String areaurl,
            @RequestParam(name = "areax") Float areax,
            @RequestParam(name = "areay") Float areay,
            @RequestParam(name = "areaid") Integer areaid
    )
    {
        BhyfDzbpArea entiy = new BhyfDzbpArea();
        entiy.setAreaname(areaname);
        entiy.setAreaurl(areaurl);
        entiy.setAreax(areax);
        entiy.setAreay(areay);
        entiy.setId(areaid);
        return ResultBody.ok().data(bhyfDzbpService.updateArea(entiy));
    }

    @ApiOperation(value = "更新地图", notes = "更新地图")
    @PostMapping("/dzbp/updatemap")
    public ResultBody<BhyfDzbpMap> updatearea(
            @RequestParam(name = "mapurl") String mapurl,
            @RequestParam(name = "mapwidth") Integer mapwidth,
            @RequestParam(name = "mapheight") Integer mapheight,
            @RequestParam(name = "mapbili") Float mapbili,
            @RequestParam(name = "mapid") Integer mapid
    )
    {
        BhyfDzbpMap entiy = new BhyfDzbpMap();
        entiy.setMapbili(mapbili);
        entiy.setMapheight(mapheight);
        entiy.setMapurl(mapurl);
        entiy.setMapwidth(mapwidth);
        entiy.setId(mapid);
        return ResultBody.ok().data(bhyfDzbpService.updateMap(entiy));
    }

    @ApiOperation(value = "获取区域列表", notes = "获取区域列表")
    @GetMapping("/dzbp/arealist")
    public ResultBody<List<BhyfDzbpArea>> getAreaListPage(
            @RequestParam(required = false) Integer gid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findAreaListPage(gid));
    }

    @ApiOperation(value = "获取地图列表", notes = "获取地图列表")
    @GetMapping("/dzbp/maplist")
    public ResultBody<List<BhyfDzbpMap>> getMapListPage(
            @RequestParam(required = false) Integer gid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.findGardenMap(gid));
    }

    @ApiOperation(value = "删除值日", notes = "删除值日")
    @PostMapping("/dzbp/deleteduty")
    public ResultBody<Boolean> deleteduty(
            @RequestParam(name = "personid") Integer personid,
            @RequestParam(name = "dutydate") String dutydate,
            @RequestParam(name = "classid") Integer classid,
            @RequestParam(name = "gid") Integer gid
    )
    {
        return ResultBody.ok().data(bhyfDzbpService.deleteDuty(personid,dutydate,gid,classid));
    }
}
